﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using NewLife.Configuration;
using NewLife.Log;
using NewLife.YWS.Entities.BLL;

public partial class Admin_System_WebLog : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            String logPath = XTrace.LogPath;
            if (Directory.Exists(logPath))
            {
                String[] files = Directory.GetFiles(logPath, "*.log", SearchOption.TopDirectoryOnly);
                if (files != null && files.Length > 0)
                {
                    foreach (String item in files)
                    {
                        DropDownList1.Items.Add(Path.GetFileNameWithoutExtension(item));
                    }
                }
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        String name = DropDownList1.SelectedValue;
        Int32 n = 0;
        if (!Int32.TryParse(name.Replace("_", null), out n) || n <= 0) return;

        String fileName = Path.Combine(XTrace.LogPath, name + ".log");
        if (!File.Exists(fileName)) return;

        //txtLog.Text = File.ReadAllText(fileName);
        using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
        {
            StreamReader reader = new StreamReader(stream);
            txtLog.Text = reader.ReadToEnd();
        }
    }
}